package org.idea.qiyu.framework.threadpool.core;

/**
 * @Author linhao
 * @Date created in 9:05 上午 2021/10/14
 */
public class InternalTask implements Runnable {

    private LinkedRunnableQueue linkedRunnableQueue;

    private volatile boolean running = true;

    private InternalTask(LinkedRunnableQueue linkedRunnableQueue){
        this.linkedRunnableQueue = linkedRunnableQueue;
    }

    @Override
    public void run() {
        while (running || !Thread.currentThread().isInterrupted()) {
            try {
                Runnable runnable = linkedRunnableQueue.take();
                runnable.run();
            }catch (Exception e){
                break;
            }
        }
    }

    public void stop(){
        this.running = false;
    }
}
